/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            serviceProvideManageInfo: {
                serviceProvides: [],
                total: 0,
                records: 1,
                moreCondition: false,
                name: '',
                conditions: {
                    id: '',
                    serviceCode: '',
                    name: '',
                    queryModel: ''
                }
            }
        },
        _initMethod: function () {
            $that.serviceProvideManageInfo.conditions.serviceCode = vc.getParam("serviceCode");
            $that._listServiceProvides(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {
            vc.on('serviceProvideManage', 'listServiceProvide', function (_param) {
                $that._listServiceProvides(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listServiceProvides(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listServiceProvides: function (_page, _rows) {
                $that.serviceProvideManageInfo.conditions.page = _page;
                $that.serviceProvideManageInfo.conditions.row = _rows;
                var param = {
                    params: $that.serviceProvideManageInfo.conditions
                };
                param.params.name = param.params.name.trim();
                param.params.serviceCode = param.params.serviceCode.trim();
                //发送get请求
                vc.http.apiGet('/serviceProvide.listServiceProvides',
                    param,
                    function (json, res) {
                        var _serviceProvideManageInfo = JSON.parse(json);
                        $that.serviceProvideManageInfo.total = _serviceProvideManageInfo.total;
                        $that.serviceProvideManageInfo.records = _serviceProvideManageInfo.records;
                        $that.serviceProvideManageInfo.serviceProvides = _serviceProvideManageInfo.data;
                        vc.emit('pagination', 'init', {
                            total: $that.serviceProvideManageInfo.records,
                            dataCount: $that.serviceProvideManageInfo.total,
                            currentPage: _page
                        });
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddServiceProvideModal: function () {
                //vc.emit('addServiceProvide','openAddServiceProvideModal',{});
                vc.jumpToPage("/#/pages/dev/devServiceProvide");
            },
            _openEditServiceProvideModel: function (_serviceProvide) {
                vc.emit('editServiceProvide', 'openEditServiceProvideModal', _serviceProvide);
            },
            _openDeleteServiceProvideModel: function (_serviceProvide) {
                vc.emit('deleteServiceProvide', 'openDeleteServiceProvideModal', _serviceProvide);
            },
            _queryServiceProvideMethod: function () {
                $that._listServiceProvides(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _resetServiceProvideMethod: function () {
                $that.serviceProvideManageInfo.conditions.id = "";
                $that.serviceProvideManageInfo.conditions.serviceCode = "";
                $that.serviceProvideManageInfo.conditions.name = "";
                $that.serviceProvideManageInfo.conditions.queryModel = "";
                $that._listServiceProvides(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.serviceProvideManageInfo.moreCondition) {
                    $that.serviceProvideManageInfo.moreCondition = false;
                } else {
                    $that.serviceProvideManageInfo.moreCondition = true;
                }
            }
        }
    });
})(window.vc);